package com.fly.common.utils;

import java.io.Serializable;
import java.util.Locale;

import com.spreada.utils.chinese.ZHConverter;

/**
 * 
 * 语言切换
 * 
 * @author 00fly
 * @version [版本号, 2016-10-21]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class LangSwitch implements Serializable
{
    /**
     * 注释内容
     */
    private static final long serialVersionUID = 8938441203225990429L;
    
    /**
     * 简体繁体转换
     * 
     * @param text 原始内容
     * @param targetLocale 转换后的目标语言类型
     * @return
     * @see [类、类#方法、类#成员]
     */
    public static String convert(String text, Locale targetLocale)
    {
        if (targetLocale == null)
        {
            return text;
        }
        if ("CN".equals(targetLocale.getCountry()))
        {
            return traToSim(text);
        }
        if ("TW,HK".contains(targetLocale.getCountry()))
        {
            return simToTra(text);
        }
        return null;
    }
    
    /**
     * 简体转繁体
     * 
     * @param simpStr 简体字符串
     * @return 繁体字符串
     */
    public static String simToTra(String simpStr)
    {
        ZHConverter converter = ZHConverter.getInstance(ZHConverter.TRADITIONAL);
        return converter.convert(simpStr);
    }
    
    /**
     * 繁体转简体
     * 
     * @param simpStr 简体字符串
     * @return 繁体字符串
     */
    public static String traToSim(String traStr)
    {
        ZHConverter converter = ZHConverter.getInstance(ZHConverter.SIMPLIFIED);
        return converter.convert(traStr);
    }
    
    /**
     * <一句话功能简述> <功能详细描述>
     * 
     * @param args
     * @see [类、类#方法、类#成员]
     */
    public static void main(String[] args)
    {
        String text = "简体转繁体";
        Locale locale1 = new Locale("zh", "CN");
        Locale locale2 = new Locale("zh", "HK");
        System.out.println(convert(text, locale1));
        System.out.println(convert(text, locale2));
    }
}
